home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMICUS04.ADF
/
C
/
freemap.c
< prev
next >
Wrap
C/C++ Source or Header
|
1985-10-30
|
13KB
|
536 lines
/* freemap.c v29 or so */
/*** Makefile ***/
V= /usr/commodore/amiga/V1
LIB= $(V)/internal/lib
SSTART= 20000
#STARTUP= /usr/commodore/amiga/V1/internal/lib/nodos_startup.obj
STARTUP= /usr/commodore/amiga/V1/internal/lib/startup.obj
# BADSTUFF= nodos.obj txwrite.obj
MAKEFILE= makefile
# MYLIBS= $(LIB)/debug.lib $(LIB)/intuition/intuition_lib.lib
MYLIBS= $(LIB)/debug.lib
FREEMAP= $(STARTUP) $(MYLIBS) freemap.obj
all: freemap.ld
freemap.ld: $(FREEMAP)
echo >$*.with "from $(FREEMAP)"
$(LINK) with=$*.with \
library=${LIBDIR}/amiga.lib \
to=$*.ld $(LFLAGS)
.INCLUDE=/usr/commodore/amiga/V1/tools/makemeta
/*** freemap.h ***/
/*** intuall.h **************************************************************
*
* intuall.h, general includer for intuition
*
* Confidential Information: Commodore-Amiga, Inc.
* Copyright (c) Commodore-Amiga, Inc.
*
* Modification History
* date author : Comments
* ------ ------ -------------------------------------
* 1-30-85 -=RJ=- created this file!
*
****************************************************************************/
#include <exec/types.h>
#include <exec/tasks.h>
#include <exec/nodes.h>
#include <exec/lists.h>
#include <exec/libraries.h>
#include <exec/ports.h>
#include <exec/interrupts.h>
#include <exec/io.h>
#include <exec/memory.h>
#include <exec/execbase.h>
/* ALWAYS INCLUDE GFX.H before any other amiga includes */
#include <graphics/gfx.h>
#include <hardware/blit.h>
#include <graphics/collide.h>
#include <graphics/copper.h>
#include <graphics/display.h>
#include <hardware/dmabits.h>
#include <graphics/gels.h>
#include <graphics/clip.h>
#include <graphics/rastport.h>
#include <graphics/view.h>
#include <graphics/gfxbase.h>
#include <hardware/intbits.h>
#include <graphics/gfxmacros.h>
#include <graphics/layers.h>
#include <graphics/text.h>
#include <hardware/custom.h>
extern struct Custom custom;
#include <devices/timer.h>
#include <devices/inputevent.h>
#include <intuition/intuition.h>
/*** freemap.c ***/
/*****************************************************************************
*
* MemMap program creates a visual diagram of free memory
*
* =Robert J. Mical=
* 11 September 1985
*
* CONFIDENTIAL and PROPRIETARY
* Copyright (C) 1985, COMMODORE-AMIGA, INC.
* All Rights Reserved
*
*
****************************************************************************/
#include "freemap.h"
#define SCREENWIDTH 320
#define SCREENHEIGHT 36
#define STARTLINE 6
#define STARTCOLUMN (2 + 4)
#define LEFTOFFSET 6
#define MENU_INFO 2
#define MENU_REDISPLAY 1
#define MENU_QUIT 0
#define SCREENBYTEWIDTH 40
#define MAPBYTEWIDTH 32 /* must be a power of two */
#define MAX_BLOCK_COUNT ((512 * 1024) >> 6)
#define printf kprintf
struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;
extern struct ExecBase *SysBase;
struct TextAttr SafeFont =
{
"topaz.font",
8,
0,
0,
};
struct IntuiText PleaseText =
{
0, 1,
JAM2,
1, 1,
NULL,
"Please",
NULL,
};
struct MenuItem PleaseItem =
{
NULL,
0, 0,
88, 9,
ITEMTEXT | ITEMENABLED | HIGHCOMP,
0,
&PleaseText,
NULL,
0,
NULL,
NULL,
};
struct Menu MapMenus[] =
{
{
NULL,
10, 0,
48, 0,
MENUENABLED,
"Info",
&PleaseItem,
},
{
&MapMenus[0],
58, 0,
88, 0,
MENUENABLED,
"Redisplay",
&PleaseItem,
},
{
&MapMenus[1],
146, 0,
48, 0,
MENUENABLED,
"Quit",
&PleaseItem,
},
};
struct NewScreen MapScreen =
{
0, 200 - SCREENHEIGHT,
SCREENWIDTH, SCREENHEIGHT, 1,
0, 1,
NULL,
CUSTOMSCREEN,
&SafeFont,
NULL,
NULL,
NULL,
};
struct NewWindow MapWindow =
{
LEFTOFFSET, 0,
(MAPBYTEWIDTH << 3) + 4, SCREENHEIGHT,
-1, -1,
MENUPICK | MENUVERIFY,
SMART_REFRESH | BACKDROP | BORDERLESS | NOCAREREFRESH,
NULL,
NULL,
NULL,
NULL,
NULL,
0, 0, 0, 0,
CUSTOMSCREEN,
};
struct Screen *MyScreen;
struct Window *MyWindow;
SHORT BitsAvailable;
SHORT BlockCount;
BYTE BitsValue;
SHORT WidthIndex;
UBYTE *MemBlock;
UBYTE *MapPointer;
ShiftMask[8] =
{
0xFF,
0X01,
0x03,
0x07,
0x0F,
0x1F,
0x3F,
0x7F,
};
RestartWindow()
{
SetRast(MyWindow->RPort, 0);
Move(MyWindow->RPort, 0, 0);
Draw(MyWindow->RPort, 0, SCREENHEIGHT - 1);
Draw(MyWindow->RPort, (MAPBYTEWIDTH << 3)+4-1, SCREENHEIGHT - 1);
Draw(MyWindow->RPort, (MAPBYTEWIDTH << 3) + 4 - 1, 0);
Draw(MyWindow->RPort, 0, 0);
}
BumpMapPointer()
{
WidthIndex++;
if (WidthIndex == MAPBYTEWIDTH)
{
WidthIndex = 0;
MapPointer += (SCREENBYTEWIDTH - MAPBYTEWIDTH + 1);
}
else MapPointer++;
}
ShiftInBits(bitcount)
SHORT bitcount;
{
SHORT shift, bytecount;
if (BitsAvailable & 0x7)
{
/* There's less than a whole byte available, so we must start
* by shifting. Get the shift amount, which will be either all
* of the bits that are available, or the block count if it's less
* than the count of the available bits
*/
if (bitcount > BitsAvailable) shift = BitsAvailable;
else shift = bitcount;
/* Shift the current contents of this byte of the map
* out of the way of our new bits.
*/
*MapPointer <<= shift;
/* The above shift shifts zero bits in from the right.
* If the current BitsValue is clear, leave them zero, else set our
* new bits.
*/
if (BitsValue) *MapPointer |= ShiftMask[shift];
/* Reduce the block count by the number of bits we just arranged */
bitcount -= shift;
/* if we've used up this memory map byte, advance to the next one */
if ((BitsAvailable -= shift) == 0)
{
BitsAvailable = 8;
BumpMapPointer();
}
}
/* Now that we've taken care of any partially completed Map bytes,
* let's check for any whole bytes that we can set (speed!)
*/
bytecount = bitcount >> 3;
while (bytecount)
{
*MapPointer = BitsValue;
BumpMapPointer();
bytecount--;
}
/* Finally, do any remaining bitcount bits to be set */
if (bitcount &= 0x7)
{
*MapPointer = BitsValue; /* Cheating, in a sense, but FAST! */
BitsAvailable = 8 - bitcount;
}
}
SHORT FindFreeBlock()
{
SHORT firstwholeblock, nextrealblock;
FOREVER
{
if (MemBlock == 0) return(0);
firstwholeblock = (MemBlock + 63) >> 6;
nextrealblock = ( MemBlock
+ ((struct MemChunk *)MemBlock)->mc_Bytes ) >> 6;
MemBlock = ((struct MemChunk *)MemBlock)->mc_Next;
if (firstwholeblock < nextrealblock)
{
BlockCount = nextrealblock - firstwholeblock;
return(firstwholeblock);
}
}
}
SetTimer(sec, micro, timermsg)
ULONG sec, micro;
struct IOStdReq *timermsg;
{
timermsg->io_Command = TR_ADDREQUEST; /* add a new timer request */
timermsg->io_Actual = sec; /* seconds */
timermsg->io_Length = micro; /* microseconds */
SendIO(timermsg); /* post a request to the timer */
}
main()
{
SHORT i, j;
struct MsgPort *timerport;
struct IOStdReq *timermsg;
struct MemHeader *MemHeader;
SHORT NextFreeBlock, NextTakenBlock;
ULONG wakeupbits, timerbit, windowbit;
struct IntuiMessage *message;
ULONG class;
USHORT code;
BOOL Redisplay;
if ((IntuitionBase = (LONG *)OpenLibrary("intuition.library", 0)) == 0)
{
printf("NO LIBRARY");
goto EXITING;
}
if ((GfxBase = (LONG *)OpenLibrary("graphics.library", 0)) == 0)
{
printf("NO LIBRARY");
goto EXITING;
}
if ((MyScreen = (struct Screen *)OpenScreen(&MapScreen)) == NULL)
{
printf("NO SCREEN");
goto EXITING;
}
ShowTitle(MyScreen, FALSE);
SetRGB4(&MyScreen->ViewPort, 0, 15, 12, 8);
SetRGB4(&MyScreen->ViewPort, 1, 8, 0, 0);
MapWindow.Screen = MyScreen;
if ((MyWindow = (struct Window *)OpenWindow(&MapWindow)) == NULL)
{
printf("NO WINDOW");
goto EXITING;
}
SetMenuStrip(MyWindow, &MapMenus[2]);
SetFont(MyWindow->RPort, OpenFont(&SafeFont));
Move(&MyScreen->RastPort, (MAPBYTEWIDTH << 3) + 8 + 4, 18);
Text(&MyScreen->RastPort, "512K", 4);
Move(&MyScreen->RastPort, (MAPBYTEWIDTH << 3) + 8 + 4, 26);
Text(&MyScreen->RastPort, "MEMORY", 6);
Move(&MyScreen->RastPort, (MAPBYTEWIDTH << 3) + 8 + 4, 34);
Text(&MyScreen->RastPort, "MAP", 3);
RestartWindow();
timerport = (struct MsgPort *)CreatePort(0, 0);
if (timerport == 0) goto EXITING;
timermsg = (struct IOStdReq *)CreateStdIO(timerport);
if (timermsg == 0) goto EXITING;
if (OpenDevice(TIMERNAME, UNIT_VBLANK, timermsg, 0) != 0)
goto EXITING;
timerbit = 1 << timerport->mp_SigBit;
windowbit = 1 << MyWindow->UserPort->mp_SigBit;
SetTimer(2, 0, timermsg);
Redisplay = TRUE;
FOREVER
{
if (Redisplay)
{
MapPointer = MyScreen->RastPort.BitMap->Planes[0];
MapPointer += (SCREENBYTEWIDTH * 2 + 1);
Forbid();
do
MemHeader = (struct MemHeader *)SysBase->MemList.lh_Head;
while ((MemHeader->mh_Attributes & MEMF_CHIP) == 0);
MemBlock = (UBYTE *)MemHeader->mh_First;
BitsAvailable = 8;
WidthIndex = 0;
NextTakenBlock = 0;
do
{
if (NextFreeBlock = FindFreeBlock())
{
BitsValue = 0;
ShiftInBits(NextFreeBlock - NextTakenBlock);
BitsValue = -1;
ShiftInBits(BlockCount);
NextTakenBlock = NextFreeBlock + BlockCount;
}
else ShiftInBits(MAX_BLOCK_COUNT - NextTakenBlock);
}
while (MemBlock);
if (NextTakenBlock < MAX_BLOCK_COUNT)
{
BitsValue = 0;
ShiftInBits(MAX_BLOCK_COUNT - NextTakenBlock);
}
Permit();
}
wakeupbits = Wait(timerbit | windowbit);
if (wakeupbits & timerbit)
{
GetMsg(timerport); /* this does nothing more than "clear" */
SetTimer(2, 0, timermsg);
}
if (wakeupbits & windowbit)
{
message = (struct IntuiMessage *)GetMsg(MyWindow->UserPort);
class = message->Class;
code = message->Code;
ReplyMsg(message);
switch (class)
{
case MENUVERIFY:
Redisplay = FALSE;
break;
case MENUPICK:
switch (MENUNUM(code))
{
case MENU_INFO:
RestartWindow();
Move(MyWindow->RPort,
STARTCOLUMN, STARTLINE);
Text(MyWindow->RPort,
"Each pixel represents 64 bytes.", 31);
Move(MyWindow->RPort,
STARTCOLUMN + 20, STARTLINE + 9);
Text(MyWindow->RPort,
"If all bytes are free, the", 26);
Move(MyWindow->RPort,
STARTCOLUMN, STARTLINE + 18);
Text(MyWindow->RPort,
"pixel is dark, else it's light.", 31);
Move(MyWindow->RPort,
STARTCOLUMN + 20, STARTLINE + 28);
Text(MyWindow->RPort,
"This trinket by =RJMical=", 26);
break;
case MENU_REDISPLAY:
RestartWindow();
case NOMENU:
Redisplay = TRUE;
break;
case MENU_QUIT:
goto EXITING;
}
}
}
}
EXITING:
if (MyWindow) CloseWindow(MyWindow);
if (MyScreen) CloseScreen(MyScreen);
if (timerport)
{
Wait(timerbit);
GetMsg(timerport);
CloseDevice(timermsg);
DeleteStdIO(timermsg);
DeletePort(timerport);
}
}